package com.example.booksdeal.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {

    final String CREATE_TABLE_SQL1 = "create table UserInfo (username primary key,password,nickname,sex,telephone)"; //创建用户信息数据表的SQL语句
    final String CREATE_TABLE_SQL2 = "create table BooksDetail (id integer primary key,username,book_name," +
            "book_type,book_price,book_oprice,book_detail,address,book_hownew,book_fuc,book_img,time)";  //创建图书信息数据表的SQL语句
    final String CREATE_TABLE_SQL3 = "create table  Comment (cmt_id integer,comment,cmt_time,username)"; //创建图书评论数据表的SQL语句
    final String CREATE_TABLE_SQL4 = "create table  ShopList (slt_id integer,username)"; //创建购买图书的数据表的SQL语句
    final String CREATE_TABLE_SQL5 = "create table  Collect (clt_id integer,username)"; //创建收藏图书的数据表的SQL语句


    private Context context;
    public DBOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, null, version);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_TABLE_SQL1);  //创建用户数据表
        sqLiteDatabase.execSQL(CREATE_TABLE_SQL2);  //创建图书信息数据表
        sqLiteDatabase.execSQL(CREATE_TABLE_SQL3);  //创建图书评论数据表
        sqLiteDatabase.execSQL(CREATE_TABLE_SQL4);  //创建购买图书的数据表
        sqLiteDatabase.execSQL(CREATE_TABLE_SQL5);  //创建收藏图书的数据表

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        Log.i("用户" , "--版本更行" + i + "-->" +i1);
    }
}
